<?php

namespace app\admin\controller;

use app\admin\validate\CompanyValidate;
use app\company\model\CompanyDividend;
use app\service\traits\Crud;
use app\admin\model\Company as CompanyModel;
use app\admin\model\CompanyUser;

class Company extends Base
{
    private CompanyModel $model;

    use Crud;

    public function initialize()
    {
        parent::initialize();
        $this->model         = new CompanyModel();
        $this->validateClass = CompanyValidate::class;
        $this->withSearch    = 'name,id';
    }

    public function format($list): mixed
    {
        return $list->each(function ($item) {
            $item->store_user = CompanyUser::where('company_id', $item->id)->admin()->field('id,user_name,mobile,real_name')->find();
            $item->dividend   = CompanyDividend::where('company_id', $item->id)->field('id,investor_id,investor_ratio,service_id,service_ratio,department_ratio,partner_ratio')->find();
        });
    }


}